package com.sgb.knowledgeshare.view.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.knowledgeshare.R;
import com.sgb.knowledgeshare.entity.VideoReceiveListEntity;
import com.sgb.knowledgeshare.view.activity.ShareUserActivity;
import com.swgk.core.BR;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

/**
 * Created by：冯齐 on 2020/11/13 09:38
 * Description：
 */
public class MagsCommentAdapter  extends BaseRecycleAdapter<VideoReceiveListEntity.RecordsBean> {
    public MagsCommentAdapter(Context context, List<VideoReceiveListEntity.RecordsBean> datas) {
        super(context, R.layout.item_share_mages_comment, datas);
    }

    @Override
    public void convert(ItemViewHolder holder,VideoReceiveListEntity.RecordsBean recordsBean) {
        holder.setBinding(BR.viewModel, recordsBean);
        ImageView magescommentlogos = holder.itemView.findViewById(R.id.mages_comment_logo);
        ImageView magescommentcover = holder.itemView.findViewById(R.id.mages_comment_cover);
        TextView magescommentname = holder.itemView.findViewById(R.id.mages_comment_name);
        TextView magescommentcontent = holder.itemView.findViewById(R.id.mages_comment_content);
        TextView magescommenttype = holder.itemView.findViewById(R.id.mages_comment_type);
        TextView magescommenttime = holder.itemView.findViewById(R.id.mages_comment_time);
        Glide.with(context).load(recordsBean.getImg())
                .apply(RequestOptions.bitmapTransform(new CircleCrop()).placeholder(R.mipmap.share_def_photo))
                .into(magescommentlogos);
        RequestOptions options = new RequestOptions()
                .bitmapTransform(new RoundedCorners(3)).override(300,300)
                .placeholder(R.mipmap.share_classify_loading)//图片加载出来前，显示的图片
                .fallback( R.mipmap.share_msage_failure) //url为空的时候,显示的图片
                .error(R.mipmap.share_msage_failure);//图片加载失败后，显示的图片
        Glide.with(context).load(recordsBean.getCover()).apply(options).into(magescommentcover);
        magescommentname.setText(recordsBean.getUserName()+"");
        if (recordsBean.getIsDeleted()==1){
            magescommentcontent.setText("该评论已删除");
            magescommentcontent.setTextColor(context.getResources().getColor(R.color.color_tab_two));
            magescommentcontent.setPadding(4,2,4,2);
            magescommentcontent.setBackgroundResource(R.drawable.share_comment_delete);
        }else {
            magescommentcontent.setText(recordsBean.getContent()+"");
            magescommentcontent.setBackgroundResource(R.color.white);
            magescommentcontent.setPadding(0,0,0,0);
            magescommentcontent.setTextColor(context.getResources().getColor(R.color.color_333333));
        }

        magescommenttime.setText(DateUtils.getDayUtils(recordsBean.getCreateTime()));
        if (recordsBean.getParentId().equals("0")){
            magescommenttype.setText("评论了你的作品");
        }else {
            magescommenttype.setText("回复了你的评论");
        }
        magescommentlogos.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShareUserActivity.start(context, recordsBean.getUser());
            }
        });
        magescommentname.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShareUserActivity.start(context, recordsBean.getUser());
            }
        });
    }
}
